//
//  MyCollectionQuestionAnswerController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/27.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "MyCollectionQuestionAnswerController.h"
#import "PersonalHomePageQuestionAnswerCell.h"

@interface MyCollectionQuestionAnswerController ()<UITableViewDelegate,UITableViewDataSource>
/**listView*/
@property (nonatomic,strong)UITableView*listView;
@property (nonatomic , strong)NSMutableArray *dataArray;


@end

@implementation MyCollectionQuestionAnswerController

- (void)loadView{
    [super loadView];
    [self.view addSubview:self.listView];
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];

}

- (void)viewDidLoad {
    [super viewDidLoad];
}
#pragma mark --UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 8.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return UIView.new;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return UIView.new;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PersonalHomePageQuestionAnswerCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([PersonalHomePageQuestionAnswerCell class]) forIndexPath:indexPath];
    PersonalHomePageQuestionAnswerOneCell * oneCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([PersonalHomePageQuestionAnswerOneCell class])];
    PersonalHomePageModel * model = self.dataArray[indexPath.row];
    model.isShare = YES;
    if (model.answerType.integerValue == 1) {
        oneCell.model = model;
        return oneCell;
    }
    cell.model = model;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    [self.navigationController pushViewController:[ImageAndTextDetailController new] animated:YES];
}
-(UITableView*)listView{
    if(!_listView){
        _listView=[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        _listView.tableFooterView = UIView.new;
        [_listView registerClass:[PersonalHomePageQuestionAnswerCell class] forCellReuseIdentifier:NSStringFromClass([PersonalHomePageQuestionAnswerCell class])];
        [_listView registerClass:[PersonalHomePageQuestionAnswerOneCell class] forCellReuseIdentifier:NSStringFromClass([PersonalHomePageQuestionAnswerOneCell class])];
        _listView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _listView.separatorColor = SeparatorColor;
    }
    return _listView;
}

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"PersonalHomePageQuestionAnswer" ofType:@"plist"];
           //当数据结构为数组时
        NSArray *array = [[NSArray alloc] initWithContentsOfFile:plistPath];
        [array enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            PersonalHomePageModel *model = [PersonalHomePageModel new];
            [model setValuesForKeysWithDictionary:obj];
            [_dataArray addObject:model];
        }];
    }
    return _dataArray;
}
@end
